<?php
namespace Home\Controller;
use Think\Controller;

class UsercheckController extends CommonController {
    const oss_appid = 'LTAI6sZcsEa0SGHc'; //OSS的APPID
    const oss_secret = '053o9lXKyeLh1J1nmlykMg0z8N0Q5E'; //OSS的APP_SECRET
    const oss_url = 'http://gxxj.oss-cn-hangzhou.aliyuncs.com';  //OSS的服务器地址
    const oss_bucket = 'gxxj';  //OSS的bucket
    const oss_file = 'adm';  //OSS的文件夹路径
    static function addossimg($image,$custom_name='')
    {
        //引入OSS类文件
        $success = new \Home\Service\OSS\OssClient(self::oss_appid, self::oss_secret, self::oss_url);
        $ext = pathinfo($image, PATHINFO_EXTENSION);
        if(empty($custom_name)){
            $img_name = time() . uniqid() . '.' . $ext;
        }else{
            $img_name = time() . uniqid() .$custom_name. '.' . $ext;
        }

        //先在oss上建一个图片存放容器，lingsui为上传路径
        $object = self::oss_file . '/' . $img_name;
        try {
            //ceshimain为bucket，即存放文件的区域，必备，区域只能有一个，但区域下面可以建多个文件夹，比如上面的lingsui文件夹
            $success->uploadFile(self::oss_bucket, $object, $image);
            //最后返回图片地址
            return self::oss_url . '/' . self::oss_file . '/' . $img_name;
        } catch (Exception $e) {
            printf(__FUNCTION__ . ": FAILED\n");
            printf($e->getMessage() . "\n");
            return false;
        }
    }
    public function upload(){
        $get = I('data');
        $get = $this->jiemi($get);
        $user_id = $get['user_id'];
        $img = $get['img'];
        $type = $get['type'];//1身份证人脸2身份证国徽3手持身份证照
        $base64_string= explode(',', $img); //截取data:image/png;base64, 这个逗号后的字符
        $data= base64_decode($base64_string[1]);//对截取后的字符使用base64_decode进行解码
        $adr = './userimg'.time().rand(0,999).$user_id.'.jpg';

        file_put_contents($adr, $data); //写入文件并保存
        $url = $this->addossimg($adr);
        if($url){
            unlink($adr);
            if($type=='1'){
                M('user_identity','',C('DB2'))->where(array('user_id'=>$user_id))->save(array('front'=>$url));
            }elseif($type=='2'){
                M('user_identity','',C('DB2'))->where(array('user_id'=>$user_id))->save(array('behind'=>$url));
            }else{
                M('user_identity','',C('DB2'))->where(array('user_id'=>$user_id))->save(array('hold'=>$url));
            }
            $has_img = M('user_identity','',C('DB2'))->where(array('user_id'=>$user_id))->field('front,behind,hold')->find();
            if($has_img['front']&&$has_img['behind']&&$has_img['hold']){
                M('user_authentication','',C('DB2'))->where(Array('user_id'=>$user_id))->setField('idcard_state','1');
            }
            $data1['ret']='1001';
            $data1['code']='上传成功';
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }else{
            $data1['ret']='1002';
            $data1['code']='上传失败';
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }
    }
    public function user_msg(){
        $get = I('data');
        $get = $this->jiemi($get);
        $user_id = $get['user_id'];
        $name = $get['name'];
        $id_card = $get['id_card'];

        $userdata = M('user','',C('DB2'))->where(array('id'=>$user_id))->field('username,identity_num,mobile')->find();
//        if($userdata['name']){
//            $data['ret']='1002';
//            $data['code']='不得重复上传个人信息';
//            $data1 = $this->jiami($data);
//            $this->return = ['data'=>$data1];
//            exit();
//        }else{
        $has_img = M('user_identity','',C('DB2'))->where(array('user_id'=>$user_id))->field('front,behind,hold')->find();
        if(!$has_img['front']||!$has_img['behind']||!$has_img['hold']){
            $data['ret']='1002';
            $data['code']='请完善身份证照片';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            exit();
        }
        //////名字验证
        if(!preg_match("/^([\xe4-\xe9][\x80-\xbf]{2}){2,4}$/",$name)){
            $data['ret']='1002';
            $data['code']='名字格式不对(二到四个汉字)';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            exit;
        }
        ////身份证验证
        if(!preg_match("/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|[xX])$/",$id_card)){
            $data['ret']='1002';
            $data['code']='身份证格式不对';
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            exit;
        }
            $res=M('user','',C('DB2'))->where(array('id'=>$user_id))->save(array('username'=>$name,'identity_num'=>$id_card));
            if($res||$res==false){
                M('user','',C('DB2'))->where(array('id'=>$user_id))->setField('user_msg_verify','2');
                M('user','',C('DB2'))->where(array('id'=>$user_id))->setField('evaluat_status','2');
                M('user_authentication','',C('DB2'))->where(Array('user_id'=>$user_id))->setField('personal','1');
                $pr_data = array();
                $pr_data["loan_date"] = date("Y-m-d", time());  // 借款日期,格式`yyyy-MM-dd`，默认当前日期
                $pr_data["name"] = $name;  // 姓名,必填
                $pr_data["id_number"] = $id_card;  // 身份证号,必填
                $pr_data["mobile"] = $userdata['mobile'];  // 手机号,必填
                $apptype = rand(1,2);
                $ret1 = pre_loan_apply($apptype, $pr_data);
                $ret = pre_loan_report($apptype, $ret1['report_id']);
                foreach ($ret['risk_items'] as $key1 => $value1) {
                    if($ret['risk_items'][$key1]['item_name']=='7天内申请人在多个平台申请借款'){
                        $count = $ret['risk_items'][$key1]['item_detail']['platform_count'];
                    }
                    if($ret['risk_items'][$key1]['item_name']=='1个月内申请人在多个平台申请借款'){
                        $count1 = $ret['risk_items'][$key1]['item_detail']['platform_count'];
                    }
                    if($ret['risk_items'][$key1]['item_name']=='3个月内申请人在多个平台申请借款'){
                        $count2 = $ret['risk_items'][$key1]['item_detail']['platform_count'];
                    }
                }
                $ad = array(
                    'user_id'=>$user_id,
                    'mobile'=>$userdata['mobile'],
                    'username'=>$name,
                    'idcard'=>$id_card,
                    'final_score' => empty($ret['final_score'])?'0':$ret['final_score'],
                    'report_id'=>$ret['report_id'],
                    'seven_day'=>empty($count)?'0':$count,
                    'one_month'=>empty($count1)?'0':$count1,
                    'three_month'=>empty($count2)?'0':$count2,
                    'ctime'=>time(),
                );
                M('get_td_data','',C('DB2_ZX'))->add($ad);
                $data['ret']  = '1001';
                $data['code'] = 'success';
//                if($user_id=='273'){
                    $data['data']['link']='https://hxgj.dstlkj.com/Dev/hxc_dev#/call';
                    $data['data']['title']='紧急联系人获取';
//                }else{
//                    $data['data']['url']='telbookUpload';
//                    $data['data']['title']='通讯录获取';
//                }
                $data['data']['islogin']='1';
                $data['data']['ishead']='1';
                $data1 = $this->jiami($data);
                $this->return = ['data'=>$data1];
                exit();
            }else{
                $data['ret']='1002';
                $data['code']='系统错误，请联系客服';
                $data['data']['url']='';
                $data1 = $this->jiami($data);
                $this->return = ['data'=>$data1];
                exit();
            }
//        }
    }
    public function mobilebook_ios(){
        $get = I('data');
        $get = $this->jiemi($get);
        $tu_id = $get['user_id'];
        $udata = $get['udata'];
        $udata = str_replace('&quot;', '', $udata);
        $udata = str_replace(array("\\","\"","\n", "{","}","\r",' ',"[","]"),'',$udata);
        $a = explode(':', $udata);
        $arr=array();
        $res = M('mobilebook','',C('DB2_ZX'))->where(array('user_id'=>$tu_id))->find();
        if($res){
            M('user','',C('DB2'))->where(array('id'=>$tu_id))->setField('contact_list','2');
            $data['ret']  = '1002';
            $data['code'] = 'success';
            $data['data']['link']='';
            $data['data']['islogin']='1';
            $data['data']['ishead']='1';
            $data['data']['title']='通讯录评测';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            exit();
        }
        foreach($a as $k=>$v){
            $count=count($a);
            if($k<$count-1){
                if($k==0){
                    $next=$k+1;
                    $udata=explode(',',$a[$next]);
                    array_pop($udata);
                    foreach($udata as $kk=>$vv){
                        $arr[$vv]=$v;
                    }

                }else{
                    $v2=end(explode(',',$v));
                    $next=$k+1;
                    $udata=explode(',',$a[$next]);
                    array_pop($udata);
                    foreach($udata as $kk=>$vv){
                        $arr[$vv]=$v2;
                    }
                }

            }
        }
        $arr1= array();
        foreach ($arr as $a => $b) {
            $arr2 = array_keys($arr1);
            if(in_array($b, $arr2)){
                $arr1[$b] = $arr1[$b].','.$a;
            }else{
                $arr1[$b] = $a;
            }
        }
        foreach ($arr1 as $key => $value) {
            $add=array(
                'user_id'=>$tu_id,
                'mail_name'=>$key,
                'mail_mobile'=>$value,
                'ctime'=>time(),
            );//

            $addnum[] = $add;
        }
        $res = M('mobilebook','',C('DB2_ZX'))->addALL($addnum);
        if($res){
            M('user','',C('DB2'))->where(array('id'=>$tu_id))->setField('contact_list','2');
            M('user_authentication','',C('DB2'))->where(Array('user_id'=>$tu_id))->setField('contact_state','1');
            $userdata = M('user','',C('DB2'))->where(array('id'=>$tu_id))->field('mobile,username as name,identity_num')->find();
            $url='https://open.shujumohe.com/box/yys?box_token=16A9D98E0C2049CBBCAD60396070BD05&cb=https://hxgj.dstlkj.com/Usercheck/call_back&real_name='.$userdata['name'].'&user_mobile='.$userdata['mobile'].'&identity_code='.$userdata['identity_num'].'&passback_params='.$tu_id;
            $data['ret']  = '1001';
            $data['code'] = 'success';
            $data['data']['link']=$url;
            $data['data']['islogin']='1';
            $data['data']['ishead']='1';
            $data['data']['title']='通讯录评测';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            exit();
        }else{
            $data['ret']  = '1002';
            $data['code'] = '系统错误请联系客服';
            $data['data']['url']='';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            exit();
        }
    }
    public function userphonebook(){
        $get = I('data');
        $get = $this->jiemi($get);
        $tu_id = $get['user_id'];
        $udata = $get['udata'];
        $res = M('mobilebook','',C('DB2_ZX'))->where(array('user_id'=>$tu_id))->find();
        if($res){
            $data['ret']  = '1001';
            $data['code'] = 'success';
            $data['data']['link']='';
            $data['data']['islogin']='1';
            $data['data']['ishead']='1';
            $data['data']['title']='运营商评测';
            $data1 = $this->jiami($data);
            $this->return = ['data'=>$data1];
            exit();
        }
        $data = str_replace('&quot;', '', $udata);

        $data = str_replace(array("\\","\"","\n", "\r","{","}",' ',"[","]"),'',$data);
        $data = explode(',', $data);
        foreach ($data as $key => $value) {
            $a = explode(':', $data[$key]);
            $add =array(
                'user_id'=>$tu_id,
                'mail_name'=>$a['0'],
                'mail_mobile'=>$a['1'],
                'ctime'=>time(),
            );
            $addnum[] =$add;
        }
        M('mobilebook','',C('DB2_ZX'))->addALL($addnum);
        $userdata = M('user','',C('DB2'))->where(array('id'=>$tu_id))->field('mobile,username as name,identity_num')->find();
        M('user','',C('DB2'))->where(array('id'=>$tu_id))->setField('contact_list','2');
        M('user_authentication','',C('DB2'))->where(Array('user_id'=>$tu_id))->setField('contact_state','1');
        $url='https://open.shujumohe.com/box/yys?box_token=16A9D98E0C2049CBBCAD60396070BD05&cb=https://hxgj.dstlkj.com/Usercheck/call_back&real_name='.$userdata['name'].'&user_mobile='.$userdata['mobile'].'&identity_code='.$userdata['identity_num'].'&passback_params='.$tu_id;
        $data['ret']  = '1001';
        $data['code'] = 'success';
        $data['data']['link']=$url;
        $data['data']['islogin']='1';
        $data['data']['ishead']='1';
        $data['data']['title']='运营商评测';
        $data1 = $this->jiami($data);
        $this->return = ['data'=>$data1];
        exit();
    }

    public function call_back(){
        $get = I('data');
        $get = $this->jiemi($get);
        $user_id = $get['user_id'];
        $task_id = $get['task_id'];
        if(empty($user_id)||empty($task_id)){
            $data1['ret']  = '1002';
            $data1['code'] = '参数错误请联系客服';
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }
        $add = array(
            'user_id'=>$user_id,
            'task_id'=>$task_id,
        );
        $t = M('tdyyshd_report','',C('DB2_ZX'))->where(array('user_id'=>$user_id))->getField('id');
        if($t){
            $data1['ret']  = '1001';
            $data1['code'] = '成功';
            M('user','',C('DB2'))->where(array('id'=>$user_id,'mobile_verify'=>'1'))->setField('mobile_verify','2');
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }else{
            $res = M('tdyyshd_report','',C('DB2_ZX'))->add($add);
        }

        if($res){
            $data1['ret']  = '1001';
            $data1['code'] = '成功';
            M('user','',C('DB2'))->where(array('id'=>$user_id,'mobile_verify'=>'1'))->setField('mobile_verify','2');
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }else{
            $data1['ret']  = '1002';
            $data1['code'] = '失败，请联系客服';
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }
    }
    public function get_dt_data(){
        header("Access-Control-Allow-Origin: *");
        $mobile = I('mobile');
        $username = I('username');
        $id_number = I('id_number');
        $app =  I('app');
        $user_id = I('user_id');
        if(empty($mobile)||empty($username)||empty($id_number)||empty($user_id)){
            $data['code']='缺少有效数据';
            $data['ret']='1002';
            $data['user_id']=$user_id;
            $data['id_number']=$id_number;
            $data['username']=$username;
            $data['mobile']=$mobile;
            $data = $this->jiami($data);
            $this->return = ['data'=>$data];
            exit();
        }
        $pr_data = array();
        $pr_data["loan_date"] = date("Y-m-d", time());  // 借款日期,格式`yyyy-MM-dd`，默认当前日期
        $pr_data["name"] = $username;  // 姓名,必填
        $pr_data["id_number"] = $id_number;  // 身份证号,必填
        $pr_data["mobile"] = $mobile;  // 手机号,必填
        $app = stripos($app, 'iP');
        if ($app === 0) {
            $apptype = 1;
        } else {
            $apptype = 2;
        }
        $ret1 = pre_loan_apply($apptype, $pr_data);
        $ret = pre_loan_report($apptype, $ret1['report_id']);
        foreach ($ret['risk_items'] as $key1 => $value1) {
            if($ret['risk_items'][$key1]['item_name']=='7天内申请人在多个平台申请借款'){
                $count = $ret['risk_items'][$key1]['item_detail']['platform_count'];
            }
            if($ret['risk_items'][$key1]['item_name']=='1个月内申请人在多个平台申请借款'){
                $count1 = $ret['risk_items'][$key1]['item_detail']['platform_count'];
            }
            if($ret['risk_items'][$key1]['item_name']=='3个月内申请人在多个平台申请借款'){
                $count2 = $ret['risk_items'][$key1]['item_detail']['platform_count'];
            }
        }
        $ad = array(
            'user_id'=>$user_id,
            'mobile'=>$mobile,
            'username'=>$username,
            'idcard'=>$id_number,
            'final_score' => empty($ret['final_score'])?'0':$ret['final_score'],
            'report_id'=>$ret['report_id'],
            'seven_day'=>empty($count)?'0':$count,
            'one_month'=>empty($count1)?'0':$count1,
            'three_month'=>empty($count2)?'0':$count2,
            'ctime'=>time(),
        );
        M('get_td_data','',C('DB2_ZX'))->add($ad);
        $data['code']='success';
        $data['ret']='1001';
        $data['data']=$ad;
        $data1 = $this->jiami($data);
        $this->return = ['data'=>$data];
        exit();
    }
    ///添加紧急联系人
    public function add_urgent_contact(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
        $user_id = $get['user_id'];
        $father_name = $get['father_name'];
        $father_number = $get['father_number'];
        $mother_name = $get['mother_name'];
        $mother_number = $get['mother_number'];
        $mate_name =$get['mate_name'];
        $mate_number = $get['mate_number'];
        $colleague_name = $get['colleague_name'];
        $colleague_number = $get['colleague_number'];
        $res=M('user','',C('DB2'))->where(array('id'=>$user_id))->field('username,mobile')->find();
        if(!empty($father_name)&&!empty($father_number)){
            //////名字验证
            if(!preg_match("/^([\xe4-\xe9][\x80-\xbf]{2}){2,4}$/",$father_name)){
                $data['ret']='1002';
                $data['code']='名字格式不对(二到四个汉字)';
                $data = $this->jiami($data);
                $this->return = ['data'=>$data];
                exit;
            }
                elseif(!preg_match("/1[345678]{1}\d{9}$/",$father_number))
                {
                    $data['ret']='1002';
                    $data['code']='手机号码格式有误';
                    $data = $this->jiami($data);
                    $this->return = ['data'=>$data];
                    exit;
                }
                    elseif($res['username']==$father_name||$res['mobile']==$father_number)
                    {
                        $data['ret']='1002';
                        $data['code']='紧急联系人不能是自己';
                        $data = $this->jiami($data);
                        $this->return = ['data'=>$data];
                        exit;
                    }
            elseif($father_name==$mother_name||$father_name==$mate_name||$father_name==$colleague_name)
            {
                $data['ret']='1002';
                $data['code']='紧急联系人姓名不能相同';
                $data = $this->jiami($data);
                $this->return = ['data'=>$data];
                exit;
            }
            elseif($father_number==$mother_number||$father_number==$mate_number||$father_number==$colleague_number)
            {
                $data['ret']='1002';
                $data['code']='紧急联系人电话不能相同';
                $data = $this->jiami($data);
                $this->return = ['data'=>$data];
                exit;
            }

        }
        elseif(!empty($mother_name)&&!empty($mother_number)){
            //////名字验证
            if(!preg_match("/^([\xe4-\xe9][\x80-\xbf]{2}){2,4}$/",$mother_name))
            {
                $data['ret']='1002';
                $data['code']='名字格式不对(二到四个汉字)';
                $data = $this->jiami($data);
                $this->return = ['data'=>$data];
                exit;
            }
                    elseif(!preg_match("/1[345678]{1}\d{9}$/",$mother_number))
                    {
                        $data['ret']='1002';
                        $data['code']='手机号码格式有误';
                        $data = $this->jiami($data);
                        $this->return = ['data'=>$data];
                        exit;
                    }
                        elseif($res['username']==$mother_name||$res['mobile']==$mother_number)
                        {
                            $data['ret']='1002';
                            $data['code']='紧急联系人不能是自己';
                            $data = $this->jiami($data);
                            $this->return = ['data'=>$data];
                            exit;
                        }
            elseif($mother_name==$mate_name||$mother_name==$colleague_name)
            {
                $data['ret']='1002';
                $data['code']='紧急联系人姓名不能相同';
                $data = $this->jiami($data);
                $this->return = ['data'=>$data];
                exit;
            }
            elseif($mother_number==$mate_number||$mother_number==$colleague_number)
            {
                $data['ret']='1002';
                $data['code']='紧急联系人电话不能相同';
                $data = $this->jiami($data);
                $this->return = ['data'=>$data];
                exit;
            }
        }
        elseif(!empty($mate_name)&&!empty($mate_number)){
            //////名字验证
            if(!preg_match("/^([\xe4-\xe9][\x80-\xbf]{2}){2,4}$/",$mate_name))
            {
                $data['ret']='1002';
                $data['code']='名字格式不对(二到四个汉字)';
                $data = $this->jiami($data);
                $this->return = ['data'=>$data];
                exit;
            }
                elseif(!preg_match("/1[345678]{1}\d{9}$/",$mate_number))
                {
                    $data['ret']='1002';
                    $data['code']='手机号码格式有误';
                    $data = $this->jiami($data);
                    $this->return = ['data'=>$data];
                    exit;
                }
                    elseif($res['username']==$mate_name||$res['mobile']==$mate_number)
                    {
                        $data['ret']='1002';
                        $data['code']='紧急联系人不能是自己';
                        $data = $this->jiami($data);
                        $this->return = ['data'=>$data];
                        exit;
                    }
                    elseif($mate_name==$colleague_name)
                    {
                        $data['ret']='1002';
                        $data['code']='紧急联系人姓名不能相同';
                        $data = $this->jiami($data);
                        $this->return = ['data'=>$data];
                        exit;
                    }
                    elseif($mate_number==$colleague_number)
                    {
                        $data['ret']='1002';
                        $data['code']='紧急联系人电话不能相同';
                        $data = $this->jiami($data);
                        $this->return = ['data'=>$data];
                        exit;
                    }
        }
        elseif(!empty($colleague_name)&&!empty($colleague_number)){
            //////名字验证
                if(!preg_match("/^([\xe4-\xe9][\x80-\xbf]{2}){2,4}$/",$colleague_name))
                {
                    $data['ret']='1002';
                    $data['code']='名字格式不对(二到四个汉字)';
                    $data = $this->jiami($data);
                    $this->return = ['data'=>$data];
                    exit;
                }
                    elseif(!preg_match("/1[345678]{1}\d{9}$/",$colleague_number))
                    {
                        $data['ret']='1002';
                        $data['code']='手机号码格式有误';
                        $data = $this->jiami($data);
                        $this->return = ['data'=>$data];
                        exit;
                    }
                        elseif($res['username']==$colleague_name||$res['mobile']==$colleague_number)
                        {
                            $data['ret']='1002';
                            $data['code']='紧急联系人不能是自己';
                        $data = $this->jiami($data);
                            $this->return = ['data'=>$data];
                            exit;
                        }
        }else{
            $data1['ret']  = '1002';
            $data1['code'] = '联系人不能为空';
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
            }
           ////紧急联系人姓名判断
            if(!empty($father_name)&&!empty($mother_name)&&!empty($mate_name)&&!empty($colleague_name))
            {
                    if($father_name==$mother_name||$father_name==$mate_name||$father_name==$colleague_name||$mother_name==$mate_name||$mother_name==$colleague_name||$mate_name==$colleague_name)
                {
                            $data1['ret']  = '1002';
                            $data1['code'] = '联系人名字相同';
                            $data1 = $this->jiami($data1);
                            $this->return = ['data'=>$data1];
                            exit();
                }
            }
                 elseif(!empty($father_name)&&!empty($mother_name))
                {
                    if($father_name==$mother_name)
                    {
                        $data1['ret']  = '1002';
                        $data1['code'] = '联系人名字相同';
                        $data1 = $this->jiami($data1);
                        $this->return = ['data'=>$data1];
                        exit();
                    }
                }
                elseif(!empty($father_name)&&!empty($mate_name))
                {
                    if($father_name==$mate_name)
                    {
                        $data1['ret']  = '1002';
                        $data1['code'] = '联系人名字相同';
                        $data1 = $this->jiami($data1);
                        $this->return = ['data'=>$data1];
                        exit();
                    }
                }
                elseif(!empty($father_name)&&!empty($colleague_name))
                {
                    if($father_name==$colleague_name)
                    {
                        $data1['ret']  = '1002';
                        $data1['code'] = '联系人名字相同';
                        $data1 = $this->jiami($data1);
                        $this->return = ['data'=>$data1];
                        exit();
                    }
                }
            elseif(!empty($father_name)&&!empty($mother_name)&&!empty($colleague_name))
            {
                if($father_name==$colleague_name||$father_name==$mother_name||$mother_name==$colleague_name)
                {
                    $data1['ret']  = '1002';
                    $data1['code'] = '联系人名字相同';
                    $data1 = $this->jiami($data1);
                    $this->return = ['data'=>$data1];
                    exit();
                }
            }
            elseif(!empty($father_name)&&!empty($mate_name)&&!empty($colleague_name))
            {
                if($father_name==$mate_name||$father_name==$colleague_name||$mate_name==$colleague_name)
                {
                    $data1['ret']  = '1002';
                    $data1['code'] = '联系人名字相同';
                    $data1 = $this->jiami($data1);
                    $this->return = ['data'=>$data1];
                    exit();
                }
            }
            //////紧急二层姓名判断
        if(!empty($mother_name)&&!empty($mate_name)&&!empty($colleague_name))
        {
            if($mother_name==$mate_name||$mother_name==$colleague_name||$mate_name==$colleague_name)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '联系人名字相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($mother_name)&&!empty($mate_name))
        {
            if($mother_name==$mate_name)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '联系人名字相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($mother_name)&&!empty($colleague_name))
        {
            if($mother_name==$colleague_name)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '联系人名字相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        ///紧急三层姓名判断
        if(empty($mate_name)&&!empty($colleague_name))
        {
            if($mate_name==$colleague_name)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '联系人名字相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }

        /////紧急联系人电话判断
        if(!empty($father_number)&&!empty($mother_number)&&!empty($mate_number)&&!empty($colleague_number))
        {
            if($father_number==$mother_number||$father_number==$mate_number||$father_number==$colleague_number||$mother_number==$mate_number||$mother_number==$colleague_number||$mate_number==$colleague_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($father_number)&&!empty($mother_number))
        {
            if($father_number==$mother_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($father_number)&&!empty($mate_number))
        {
            if($father_number==$mate_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($father_number)&&!empty($colleague_number))
        {
            if($father_number==$colleague_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($father_number)&&!empty($mother_number)&&!empty($colleague_number))
        {
            if($father_number==$colleague_number||$father_number==$mother_number||$mother_number==$colleague_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($father_number)&&!empty($mate_number)&&!empty($colleague_number))
        {
            if($father_number==$mate_number||$father_number==$colleague_number||$mate_number==$colleague_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        ////// /////紧急联系人电话判断 二层组合
        if(!empty($mother_number)&&!empty($mate_number)&&!empty($colleague_number))
        {
            if($mother_number==$mate_number||$mother_number==$colleague_number||$mate_number==$colleague_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($mother_number)&&!empty($mate_number))
        {
            if($mother_number==$mate_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        elseif(!empty($mother_number)&&!empty($colleague_number))
        {
            if($mother_number==$colleague_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }
        /////紧急联系人电话判断
        if(empty($mate_number)&&!empty($colleague_number))
        {
            if($mate_number==$colleague_number)
            {
                $data1['ret']  = '1002';
                $data1['code'] = '紧急联系人电话相同';
                $data1 = $this->jiami($data1);
                $this->return = ['data'=>$data1];
                exit();
            }
        }

//            if($father_name==$mother_name||$father_name==$mate_name||$father_name==$colleague_name||$mother_name==$mate_name||$mother_name==$colleague_name||$mate_name==$colleague_name)
//            {
//                        $data1['ret']  = '1002';
//                        $data1['code'] = '联系人名字相同';
//                        $data1 = $this->jiami($data1);
//                        $this->return = ['data'=>$data1];
//                        exit();
//            }
//        if($father_number==$mother_number||$father_number==$mate_number||$father_number==$colleague_number||$mother_number==$mate_number||$mother_number==$colleague_number||$mate_number==$colleague_number)
//        {
//            $data1['ret']  = '1002';
//            $data1['code'] = '联系人电话相同';
//            $data1 = $this->jiami($data1);
//            $this->return = ['data'=>$data1];
//            exit();
//        }

        if(empty($user_id)){
            $data1['ret']  = '1002';
            $data1['code'] = '请先登录';
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }
        $user_urgent_data = M('user_exigence','',C('DB2'))->where(array('user_id'=>$user_id))->field('parent,parent_mobile,mother,mother_mobile,mate,mate_mobile,workmate,workmate_mobile')->find();
        if(empty($user_urgent_data)){
            M('user_exigence','',C('DB2'))->add(array('user_id'=>$user_id,'ctime'=>time()));
        }
        $edit_urgent = array(
            'parent'=>empty($father_name)?$user_urgent_data['parent']:$father_name,
            'parent_mobile'=>empty($father_number)?$user_urgent_data['parent_mobile']:$father_number,
            'mother'=>empty($mother_name)?$user_urgent_data['mother']:$mother_name,
            'mother_mobile'=>empty($mother_number)?$user_urgent_data['mother_mobile']:$mother_number,
            'mate'=>empty($mate_name)?$user_urgent_data['mate']:$mate_name,
            'mate_mobile'=>empty($mate_number)?$user_urgent_data['mate_mobile']:$mate_number,
            'workmate'=>empty($colleague_name)?$user_urgent_data['workmate']:$colleague_name,
            'workmate_mobile'=>empty($colleague_number)?$user_urgent_data['workmate_mobile']:$colleague_number,
        );
        M('user_exigence','',C('DB2'))->where(array('user_id'=>$user_id))->save($edit_urgent);
        M('user','',C('DB2'))->where(Array('id'=>$user_id))->setField('urgent_verify','1');
        $data['code']='success';
        $data['ret']='1001';
        $data['data']['url']='';
        $data['data']['link']='https://hxgj.dstlkj.com/Dev/hxc_dev#/company';
        $data['data']['islogin']='1';
        $data['data']['ishead']='1';
        $data['data']['title']='通讯录获取';
        $data1 = $this->jiami($data);
        $this->return = ['data'=>$data1];
        exit();
    }
    public function work_add(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
        $user_id = $get['user_id'];
        $company_name = $get['company_name'];
        $company_address =$get['company_address'];
        $company_number = $get['company_number'];
        $income = $get['income'];
        $user_work_data = M('user','',C('DB2'))->where(array('id'=>$user_id))->field('company,company_address,company_mobile,salary')->find();
        if(empty($user_id)){
            $data1['ret']  = '1002';
            $data1['code'] = '请先登录';
            $data1 = $this->jiami($data1);
            $this->return = ['data'=>$data1];
            exit();
        }
        $edit_work = array(
            'company'=>empty($company_name)?$user_work_data['company']:$company_name,
            'company_address'=>empty($company_address)?$user_work_data['company_address']:$company_address,
            'company_mobile'=>empty($company_number)?$user_work_data['company_mobile']:$company_number,
            'salary'=>empty($income)?$user_work_data['salary']:$income,
            'company_verify'=>'1'
        );
        M('user','',C('DB2'))->where(array('id'=>$user_id))->save($edit_work);
        $data['code']='success';
        $data['ret']='1001';
//        $data['data']['url']='telbookUpload';
        $data['data']['link']='';
        $data['data']['islogin']='1';
        $data['data']['ishead']='1';
        $data['data']['title']='通讯录获取';
        $data1 = $this->jiami($data);
        $this->return = ['data'=>$data1];
        exit();
    }
    public function user_urgent_data(){
        header("Access-Control-Allow-Origin: *");
        $get = I('data');
        $get = $this->jiemi($get);
        $user_id = $get['user_id'];
        $user_data = M('user','',C('DB2'))->alias('a')->join('left join t_user_exigence b on a.id = b.user_id')->where(array('a.id'=>$user_id))->field('a.company,a.company_address,a.company_mobile,a.salary,b.parent,b.parent_mobile,b.mother,b.mother_mobile,b.mate,b.mate_mobile,b.workmate,b.workmate_mobile')->find();
        $isnull = empty($isnull)?'1':'0';
        $data['code']='success';
        $data['ret']='1001';
        $data['data']=$user_data;
        $data['isnull']=$isnull;
        $data1 = $this->jiami($data);
        $this->return = ['data'=>$data1];
        exit();
    }

    public function del_ceshi(){
        $has = M('user','',C('DB2'))->where(Array('mobile'=>'15225170185'))->getField('id');
        if($has){
            M('user','',C('DB2'))->where(Array('mobile'=>'15225170185'))->delete();
            $has1 = M('mobile_basicinfo','',C('DB2_ZX'))->where(array('user_id'=>$has))->getField('id');
            if($has1){
                M('mobile_basicinfo','',C('DB2_ZX'))->where(array('user_id'=>$has))->delete();
            }
        }
        echo '成功';
    }


}